package com.me.model;

import com.me.annotation.Ignore;
import com.me.enums.OrderStatus;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;

public class Order {
    private String id;
    private BigDecimal total;
    private int amount;
    private int status;
    private int payType;
    private String name;
    private String phone;
    private String address;
    private String datetime;
    private String userId;

	@Ignore private Collection<Orderitem> ois;

	public Order() { }

	public Order(User u) {
		this.id = UUID.randomUUID().toString();
		this.total = BigDecimal.valueOf(0);
		this.amount = 0;
		this.status = OrderStatus.uncommit;
		this.payType = -1;
		this.name = u.getName();
		this.phone = u.getPhone();
		this.address = u.getAddress();
		this.userId = u.getId();
		refreshTime();
	}

	public void refreshTime() {
		Date d = new Date();
		this.datetime = String.format("%1$tY-%1$tm-%1$td %2$tH:%2$tM:%2$tS", d, d.getTime());
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public float getTotal() {
        return total.floatValue();
    }

	public BigDecimal getDTotal() {
        return total;
    }

    public void setTotal(float total) {
        this.total = BigDecimal.valueOf(total);
    }

	public void setTotal(BigDecimal total) {
		this.total = total;
	}

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getPayType() {
		return payType;
	}

	public void setPayType(int payType) {
		this.payType = payType;
	}

	public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

	public String getDatetime() {
		return datetime;
	}

	public void setDatetime(String datetime) {
		this.datetime = datetime;
	}

	public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

	public Collection<Orderitem> getOis() {
		return ois;
	}

	public void setOis(Collection<Orderitem> ois) {
		this.ois = ois;
	}
}